package cn.huiyunche.bms.backend.service;

import cn.huiyunche.bms.base.mapper.BAreaMapper;
import cn.huiyunche.bms.base.model.BArea;
import cn.huiyunche.bms.base.model.BAreaExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Felix on 2017/7/6 9527.
 */
@Service
public class AreaServiceImpl implements AreaService{
    @Autowired
    private BAreaMapper areaMapper;
    private static final Logger LOGGER = LoggerFactory.getLogger(AreaServiceImpl.class);

    @Override
    public List<BArea> queryByCode(String code) throws Exception {
        BAreaExample example = new BAreaExample();
        if (code != null) {
            LOGGER.error("AreaServiceImpl.queryByCode param code must not be null ");
            throw new IllegalArgumentException("code");
        }
        example.createCriteria().andCodeEqualTo(code);
        List<BArea> list = areaMapper.selectByExample(example);
        return list;
    }

    @Override
    public List<BArea> queryByParentCode(String parentCode) throws Exception {
        BAreaExample example = new BAreaExample();
        if (parentCode == null){
            LOGGER.error("AreaServiceImpl.queryByParentCode param parentCode not be null ");
            throw new IllegalArgumentException("parentCode不能为空");
        }
        example.createCriteria().andParentCodeEqualTo(parentCode);
        List<BArea> list = areaMapper.selectByExample(example);
        return list;
    }

    @Override
    public List<BArea> queryProvince() throws Exception {
        BAreaExample example = new BAreaExample();
        example.createCriteria().andLevelEqualTo("1");
        List<BArea> list = areaMapper.selectByExample(example);
        return list;
    }
}



